<?php


use yii\db\Migration;

/**
 * Class m210708_141231_user_create_admin
 */
class m210708_141231_user_create_admin extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $user = new \common\models\User();
        $user->username = "admin";
        $user->email = "chenzhiweiwk@qq.com";
        $user->status = \common\models\User::STATUS_ACTIVE;
        $user->setPassword("123456");
        $user->generateAuthKey();
        return $user->save();
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        \common\models\User::deleteAll(["username" => "admin"]);
        return true;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m210708_141231_user_create_admin cannot be reverted.\n";

        return false;
    }
    */
}
